From 98bd1f744810b1ac53e429cfb09b20986a450dd0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 29 Jan 2015 11:41:00 -0800 Subject: [PATCH] Don't require all submodules are checked out When probing a repository for files that should be considered as inputs for a build script we should just skip submodules that haven't been checked out instead of throwing an error. Closes #1248 --- src/cargo/sources/path.rs | 5 ++++- tests/test_cargo_compile_git_deps.rs | 32 +++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 3fc6990f2..079c892a2 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -155,7 +155,10 @@ impl<'a, 'b> PathSource<'a, 'b> { human(format!("invalid utf-8 filename: {}", rel.display())) })); let submodule = try!(repo.find_submodule(rel)); - let repo = try!(submodule.open()); + let repo = match submodule.open() { + Ok(repo) => repo, + Err(..) => continue, + }; let files = try!(self.list_files_git(pkg, repo, filter)); ret.extend(files.into_iter()); } else if (*filter)(&file_path) { diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 7555c94a8..e04f2f5ed 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -6,7 +6,7 @@ use git2; use support::{ProjectBuilder, project, execs, main_file}; use support::{cargo_dir, path2url}; use support::{COMPILING, UPDATING, RUNNING}; -use support::paths::PathExt; +use support::paths::{self, PathExt}; use hamcrest::{assert_that,existing_file}; use cargo; use cargo::util::{ProcessError, process}; @@ -1651,3 +1651,33 @@ test!(switch_sources { {compiling} project v0.5.0 ([..]) ", updating = UPDATING, compiling = COMPILING).as_slice())); }); + +test!(dont_require_submodules_are_checked_out { + let project = project("foo"); + let git1 = git_repo("dep1", |p| { + p.file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + build = "build.rs" + "#) + .file("build.rs", "fn main() {}") + .file("src/lib.rs", "") + }).unwrap(); + let git2 = git_repo("dep2", |p| p).unwrap(); + + let repo = git2::Repository::open(&git1.root()).unwrap(); + let url = path2url(git2.root()).to_string(); + add_submodule(&repo, url.as_slice(), &Path::new("submodule")); + commit(&repo); + + git2::Repository::init(&project.root()).unwrap(); + let url = path2url(git1.root()).to_string(); + let dst = paths::home().join("foo"); + git2::Repository::clone(&url[], &dst).unwrap(); + + assert_that(git1.process(cargo_dir().join("cargo")).arg("build").arg("-v") + .cwd(dst), + execs().with_status(0)); +}); -- 2.30.2